<?php

/**
 * Resource model. Uses the module/controller/action of the request
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: Resources.php 38 2009-02-18 17:12:39Z monzee $
 */
class Admin_Resources
{
    static protected $_resourceNameSpec = ':module/:controller/:action';

    /**
     * Get resource id
     * 
     * $params must contain the keys 'module', 'controller' and 'action'
     * 
     * @param array $params Uses the current request if not passed
     * @return string
     */
    static public function getResource(array $params = null)
    {
        if (null !== $params) {
            $module = $params['module'];
            $controller = $params['controller'];
            $action = $params['action'];
        } else {
            $req = Zend_Controller_Front::getInstance()->getRequest();
            $module = $req->getModuleName();
            $controller = $req->getControllerName();
            $action = $req->getActionName();
        }

        $replaceMap = array(
            ':module' => $module,
            ':controller' => $controller,
            ':action' => $action,
        );

        return str_replace(array_keys($replaceMap), array_values($replaceMap),
            self::$_resourceNameSpec);
    }

}
